<?php
/**
 * Created by PhpStorm.
 * User: 4399-0661
 * Date: 15-5-12
 * Time: 下午6:41
 */

namespace Library\route;


class LibHtml extends LibBase
{
    /**
     * /sae/index-index-id-11-rr-2-rr-3
     * 路由算法
     */
    public function action()
    {
        $urlArr = explode("/", trim($this->url, "/"));
        $this->application = $this->filter($urlArr[0], true);
        if (!file_exists(SYS_APPLICATION . $this->application)) {
            //\LibLog::custom("Applitacion Not Exists:" . SYS_APPLICATION . $this->application);
            exit();
        }
        if (!isset($urlArr[1])) {
            $this->module = DEFAULT_MODULE;
            $this->method = DEFAULT_METHOD;
            return false;
        }
        $modArr = explode("-", trim($urlArr[1]));
        $this->module = $this->filter($modArr[0], true);
        unset($modArr[0]);
        !$this->module && $this->module = DEFAULT_MODULE;
        $len = count($modArr);
        if ($modArr && $len % 2 > 0) {
            $this->method = $this->filter($modArr[1]);
            unset($modArr[1]);
        } else {
            $this->method = DEFAULT_METHOD;
        }
        $params = array_values($modArr);
        for ($i = 0; $i < count($params); $i += 2) {
            $_GET[$params[$i]] = $params[$i + 1];
            $_REQUEST[$params[$i]] = $params[$i + 1];
        }
        unset($_GET['_RW_']);
        unset($_REQUEST['_RW_']);
    }
} 